﻿using PrjAssess.Models;
using PrjAssess.Models.Service.AssessProject;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace PrjAssess.Controllers
{
    public class ProjectManageController : Controller
    {
        //
        // GET: /ProjectManage/

        public ActionResult Index()
        {
            List<PrjItem> Items = ProjectDataHelper.GetAllPrjList();
            return View(Items);
        }


        [HttpPost]
        public JsonResult GetPrjList()
        {
            //dynamic list = ProjectDataHelper.GetAllPrjList();
            List<PrjItem> Items = ProjectDataHelper.GetAllPrjList();
            return Json(Items);
        }
        [HttpPost]
        public JsonResult SetCurPrj(string prjId,string prjName)
        {
            PrjItem item = new PrjItem()
            {
                Id = prjId,
                Name = prjName
            };
            GlobalData.CurPrj = item;
            return Json("1");
        }
        [HttpPost]
        public JsonResult DeletePrj()
        {
            try
            {
                if (GlobalData.CurPrj != null)
                {
                    ProjectDataHelper.DeleteByPrjId(GlobalData.CurPrj.Id);
                }
                GlobalData.CurPrj = null;
                return Json("1");
            }
            catch
            {
                return Json("0");
            }
        }
    }
}
